<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> bind方法应用 </title>
</head>
<body>
    <button>获取验证码</button>
</body>
<script>
    let total = 20;
    let second =total;
    document.querySelector('button');
    document.addEventListener  ('click',e =>{
                console.log(e.target);
              //要修改setText函数的this指向
             //不能立即执行，需要靠定时器循环执行      
             let timer = setInterval(setText.bind(e.target), 1000);   
    });
    function setText(){
        //这里需要将this指向按钮，方便修改按钮文字
        this.innerText = second +'秒后重新获取';
         second--;  
    }
</script>
</html>